home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / math / alged34.zip / ALGEDSRC.ZIP / ALGED.H < prev    next >
C/C++ Source or Header  |  1996-06-06  |  5KB  |  172 lines

  1. /*--------------------------------------------------------------------
  2.    Alged:  Algebra Editor    henckel@vnet.ibm.com
  3.  
  4.    Copyright (c) 1994 John Henckel
  5.    Permission to use, copy, modify, distribute and sell this software
  6.    and its documentation for any purpose is hereby granted without fee,
  7.    provided that the above copyright notice appear in all copies.
  8. */
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <math.h>
  13. #include <conio.h>
  14. #include <time.h>
  15. #include "mouse.h"
  16.  
  17. #define MAXP 5
  18. #define MAXM 50
  19. typedef unsigned char uchar;
  20.  
  21. #ifndef __IBMC__
  22. extern void _floatconvert();        /* force load float libs */
  23. #pragma extref _floatconvert
  24. #endif
  25.  
  26. /*-----------------------------------------------------------------
  27.    The following is the fundamental data structure for alged.
  28.    >> when you create a new node you need to set kind,nump,parm,
  29.    and name (or value for NUMbers).
  30.    >> tag is used to debug memory problems, if the node is allocated
  31.    then it should be 12345, else it should not be.
  32.    >> sx,sy,px,py,ay are set by the display functions and used by the
  33.    findnode.  name is set for numbers only.
  34.    >> ay is used to adjust the visual appearance of vertically stacked
  35.    operations like EXP and DIV.
  36. */
  37. typedef struct node {
  38.   char name[8];
  39.   struct node *parm[MAXP];
  40.   short tag;
  41.   double value;
  42.   short sx,sy;       /* size */
  43.   short px,py;      /* location on scrn */
  44.   short ay;         /* adjust y */
  45.   short kind;
  46.   short nump;
  47.   char *msg;
  48.   struct node *next;
  49. } node;
  50.  
  51.  
  52. /* note: you may add to the end of this list, but don't insert or change
  53.    the order */
  54. enum KIND { EQU,FUN,ADD,SUB,MUL,DIV,EXP,VAR,NUM,BAD };
  55. enum menui {
  56.     SIM, ASS, PCO, PLY, SBS, ADZ, SUZ, CLR,
  57.     DIS, COD, PRV, QUA, EXX, MUZ, DEL, LOD,
  58.     CAL, CH8, NXT, FAP, EXJ, DIZ, INK, SAV,
  59.     RAT, PPL, PP0, PPR, EQK, EXZ, ENT, WRI,
  60.     HLP, PRI, ESC, CUB, GRF, XE0, P2K, P2L,
  61.     P2R, P2T, XE1, DEK, DI2, SI2, maxm };
  62.  
  63. /*--------------------------------------------------------------------
  64.    MACROS
  65. */
  66. #define setmax(x,y) if ((x)<(y)) x=(y)
  67. #define relxy(x,y) gotoxy(wherex()+(x),wherey()+(y))
  68. #define lf parm[0]
  69. #define rt parm[1]
  70. #define pause delay(1000)
  71. /*-----------------------------------------------------------------
  72.    Function Prototypes
  73. */
  74. void checknull(void *p);
  75. node *newnode(void);
  76. node *newnum(double val);
  77. node *newvar(char *s);
  78. node *newoper(int kind);
  79. void freenode(node *p);
  80. void freetree(node *p);
  81. void nodecpy(node *a, node *b);
  82. void movenode(node *a, node *b);
  83. node *cons(node *left,int opr,node *right);
  84. node *deepcopy(node *p);
  85. int equal(node *p,node *q);
  86. node *lastnode(node *p);
  87. node *prevnode(node *p);
  88. int cmp(node *p,node *q);
  89. int sortnode(node *p,int oper);
  90. void primefact(node *p);
  91. int rational_search(node *p);
  92. int reduce(double *a,double *b);
  93. int ration(node *p);
  94. void associate(node *p);
  95. int expjoin(node *p);
  96. int nosubdiv(node *p);
  97. int bisect(node *p);
  98. int exexpand(node *p);
  99. int comdeno(node *p);
  100. int distribute2(node *p);
  101. int distribute(node *p);
  102. int distribute_c(node *p);
  103. int fixassoc(node *p);
  104. int movenums(node *p,int up,int oper);
  105. int calcnode(node *p,int keeprat);
  106. node *get_term(node *p, int oper, double *r);
  107. int combine(node *p);
  108. node *maketree(node **coef, int sz, node *base);
  109. int findbase(node *a, node *b);
  110. node **maketable(node *base, node *p, int *size);
  111. node *polydiv(node *base, node *nm, node *dn);
  112. void polycoef(node *base, node *p);
  113. void quadratic(node *base,node *p);
  114. void cross_eq(node *p, int i);
  115. void cubic(node *base,node *pol);
  116. node *nextfact(node *p,int i);
  117. node *checkroot(node *base, node *p, node *den);
  118. void factrpoly(node *base,node *p);
  119. void twirl(void);
  120. void dumpnode(node *p,int tab);
  121. void resize(node *p,int ppr);
  122. void leftpar(int h);
  123. void rightpar(int h);
  124. int fixattr(node *p);
  125. void show(node *p,int ppr,int x,int y);
  126. long countmem();
  127. void show_menu(void);
  128. int selection(int x, int y);
  129. void display(node *p);
  130. int debug(node *p);
  131. void simplify(node *p);
  132. void simplify2(node *p,int slow);
  133. node *load(char *filename);
  134. node *loadinfix(char *filename);
  135. node *reverse(node *b);
  136. void loadfile(char *fn);
  137. void fprinttree(FILE *f,node *p);
  138. void graph(node *fx,node *fy);
  139. void putmsg(FILE *f,char *m);
  140. void savefile(char *fn);
  141. void fwritetree(FILE *f,node *p,int pr);
  142. void writefile(char *fn);
  143. node *find_node(node *p,int x,int y);
  144. void substitution(node *p);
  145. void insertkey(int opr);
  146. char *keyin(char *pmt);
  147. void showhelp(char *arextern0);
  148. int loadmenu(char *arextern0);
  149. /*-----------------------------------------------------------------
  150.    some macros used by simplify
  151. */
  152. #define swingb do { \
  153.       p->rt = b->rt; \
  154.       b->rt = b->lf; \
  155.       b->lf = p->lf; \
  156.       p->lf = b; } while(0)
  157. #define swinga do { \
  158.       p->lf = a->lf; \
  159.       a->lf = a->rt; \
  160.       a->rt = p->rt; \
  161.       p->rt = a; } while(0)
  162. #define aop(x) ((x)==ADD || (x)==SUB)
  163.  
  164. #define whole(x) (fmod((x),1)==0)
  165.  
  166. /* end of file alged.h */
  167. #ifdef MAIN
  168. #include "algmain.h"
  169. #else
  170. #include "algvars.h"
  171. #endif
  172.